<?php
/**
 * Yii view _list
 *
 * @author nguyenmanhluu
 * @since Aug 8, 2013 - 7:25:54 PM
 */
?>
<div class="row-fluid">
    <?php if ($this->checkAccess('create', '', TRUE)): ?>
        <?php if (isset($this->model->createUrl)): ?>
            <div class="span4">
                <p>
                    <a href="<?php echo $this->model->createUrl; ?>"
                       class="btn btn-primary" onclick="return newItem();" >
                        <i class="icon-plus"></i> <?php echo isset($this->createLabel) ? $this->createLabel : 'Add ' . $this->title ?>
                    </a>
                </p>
            </div>
        <?php endif; ?>
    <?php endif; ?>
    <div class="span8">
        <?php if (Yii::app()->user->hasFlash('success')): ?>
            <div class="alert alert-success">
                <button type="button" class="close" data-dismiss="alert">×</button>
                <?php echo Yii::app()->user->getFlash('success'); ?>
            </div>
        <?php elseif (Yii::app()->user->hasFlash('error')): ?>
            <div class="alert alert-error">
                <button type="button" class="close" data-dismiss="alert">×</button>
                <?php echo Yii::app()->user->getFlash('error'); ?>
            </div>
        <?php endif; ?>
    </div>
</div>
<div class="table-responsive">
    <table class="table table-bordered table-striped table-condensed">
        <thead>
            <tr>
                <?php foreach ($this->listColumns as $column => $opts): ?>
                    <th><?php echo $this->model->getAttributeLabel($column) ?></th>
                <?php endforeach; ?>

                <?php if ($this->checkAccess('edit', '', TRUE) or $this->checkAccess('delete', '', TRUE)): ?>
                    <th></th>
                <?php endif; ?>
            </tr>
        </thead>   
        <tbody>
            <?php if ($data): ?>
                <?php foreach ($data as $item): ?>
                    <tr data="<?php $item->id ?>">
                        <?php foreach ($this->listColumns as $column => $opts): ?>
                            <td>
                                <?php
                                if (isset($opts['value']))
                                {
                                    $val = '';
                                    eval("\$val = " . $opts['value'] . ";");
                                    echo isset($opts['pendValue']) ? $val . $opts['pendValue'] : $val;
                                    unset($val);
                                }
                                else
                                {
                                    echo $item->{$column};
                                }
                                ?>
                            </td>
                        <?php endforeach; ?>
                        <?php if ($this->checkAccess('edit', '', TRUE) or $this->checkAccess('delete', '', TRUE)): ?>
                            <td class="center">
                                <?php if (isset($item->editUrl)): ?>
                                    <?php if ($this->checkAccess('edit', '', TRUE)): ?>
                                        <a href="<?php echo $item->editUrl ?>" class="btn btn-info"
                                           onclick="return editItem($(this))">
                                            <i class="icon-edit "></i>                                            
                                        </a>
                                    <?php endif; ?>
                                <?php endif; ?>
                                <?php if (isset($item->deleteUrl)): ?>
                                    <?php if ($this->checkAccess('delete', '', TRUE)): ?>
                                        <a class="btn btn-danger" href="<?php echo $item->deleteUrl ?>"
                                           onclick="return deleteItem($(this))">
                                            <i class="icon-trash "></i> 
                                        </a>
                                    <?php endif; ?>
                                <?php endif; ?>

                            </td>                                       
                        <?php endif; ?>
                    </tr>                             
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
</div>
<div class="pagination pagination-centered">    
    <?php
    $this->widget('application.widgets.MyLinkPager', array(
        'pages'                => $pages,
        'header'               => '',
        'maxButtonCount'       => 5,
        'nextPageLabel'        => '&raquo;',
        'firstPageLabel'       => '←',
        'lastPageLabel'        => '→',
        'prevPageLabel'        => '&laquo;',
        'selectedPageCssClass' => 'active',
    ))
    ?>
</div>